export const baseURL = 'https://horse.molijuhe.com'

export default function request(config = {}){
  return new Promise((reslove,reject)=>{
    if(config.url !== '/api/index/get_users' && config.url !== '/api/index/get_openid' && config.url !== '/api/mall/mall' && config.url !== '/api/mall/shop'){
      if(!wx.getStorageSync('uid')){
        wx.showToast({
          title:'请先登录!',
          icon:'error'
        })
        setTimeout(() => {
          wx.switchTab({
            url: '/pages/me/index',
          })
        }, 1000);
        return
      }
    }
    wx.request({
      url: baseURL + config.url,
      data:config.data,
      method:config.method || 'GET',
      success:(res)=>{
        reslove(res.data)
      },
      fail:(res)=>{
        reject('服务器异常，请稍后重试！')
      }
    })
  })
}